package com.wwj.aicodemother.core.saver;

import cn.hutool.core.util.StrUtil;
import com.wwj.aicodemother.AI.model.MultiFileCodeResult;
import com.wwj.aicodemother.exception.BusinessException;
import com.wwj.aicodemother.exception.ErrorCode;
import com.wwj.aicodemother.model.enums.CodeGenTypeEnum;

public class MultiFileCodeFileSaverTemplate extends CodeFileSaverTemplate<MultiFileCodeResult>{

/**
 * 验证输入的HTML代码结果
 * @param result 包含HTML代码的结果对象
 * @throws BusinessException 当HTML代码为空时抛出业务异常
 */
    @Override
    protected void validateInput(MultiFileCodeResult result) {
        super.validateInput(result);
        if (StrUtil.isBlank(result.getHtmlCode())) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "html代码不能为空");
        }
    }

    @Override
    protected CodeGenTypeEnum getCodeType() {
        return CodeGenTypeEnum.MULTI_FILE;
    }

    @Override
    protected void saveFile(MultiFileCodeResult result, String baseDirPath) {
        writeToFile(baseDirPath, "index.html", result.getHtmlCode());
        writeToFile(baseDirPath, "script.js", result.getJsCode());
        writeToFile(baseDirPath, "style.css", result.getCssCode());
    }
}
